mod config;
mod database;
mod logger;

use axum::{Router, debug_handler, routing};
use tokio::net::TcpListener;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // 初始化日志
    logger::init();
    // 初始化数据库
    let db = database::init().await?;
    // 路由
    let router = Router::new().route("/", routing::get(index));
    // 获取端口
    let port = config::get().server().port();
    // 监听器
    let listener = TcpListener::bind(format!("0.0.0.0:{port}")).await?;
    tracing::info!("start http://0.0.0.0:{port}");
    // serve
    axum::serve(listener, router).await?;
    Ok(())
}

#[debug_handler]
async fn index() -> &'static str {
    "hello world"
}
